cmake_minimum_required(VERSION 3.15) 
project(same_library_demo)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib1)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib2)

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src STRING_DEMO_SRC_FILES)
set(STRING_DEMO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
message(STRING_DEMO_SRC_FILES=${STRING_DEMO_SRC_FILES})
message(STRING_DEMO_INCLUDE_DIR=${STRING_DEMO_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${STRING_DEMO_SRC_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE ${STRING_DEMO_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib1/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib2/include)

# 链接顺序决定屏蔽谁的公共接口，使用谁的接口
target_link_libraries(${PROJECT_NAME} PUBLIC lib2 lib1)